package com.superman.service.impl;

import com.superman.dao.IUserDao;
import com.superman.dao.impl.UserDaoImpl;
import com.superman.entity.User;
import com.superman.service.ILoginAndRegister;

import java.sql.SQLException;

public class LoginAndRegisterImpl implements ILoginAndRegister {
    IUserDao userDao = new UserDaoImpl();

    /**
     * 登录
     * @param user
     * @return 当前登录用户对象
     */
    @Override
    public User login(User user) {
        User userReturn = null;
        try {
            userReturn = userDao.singleQueryUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            return userReturn;
        }
    }

    /**
     * 注册
     * @param user
     * @return 注册语句添加行数
     */
    @Override
    public String register(User user) {
        int row = -1;
        try {
            row = userDao.insertUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            return String.valueOf(row);
        }
    }
}
